<template>
  <div class="child-left-header" :class="{ 'child-border-bottom': curFlowType === flowStart }">
    <img :src="typeIcon" />
    <span>流程分类</span>
  </div>
  <div v-if="curFlowType === flowCheck" class="child-left-tree">
    <flow-check />
  </div>
  <div v-if="curFlowType === flowStart" class="child-left-start">
    <flow-start />
  </div>
  <flow-footer />
</template>

<script>
  import { defineComponent, reactive, toRefs, onBeforeUnmount, onMounted } from 'vue';
  import FlowCheck from '@/views/board-home/components/flow-check.vue';
  import FlowStart from '@/views/board-home/components/flow-start.vue';
  import FlowFooter from '@/views/board-home/components/flow-footer.vue';
  import typeIcon from '@/assets/type-icon.png';
  import VueEvent from '@/helper/event';
  import { HOME_FLOW_SWITCH, HOME_FLOW_CHECK, HOME_FLOW_START } from '@/helper/constant';
  export default defineComponent({
    name: 'FlowType',
    components: {
      FlowCheck,
      FlowStart,
      FlowFooter,
    },
    setup() {
      const state = reactive({
        typeIcon,
        curFlowType: HOME_FLOW_CHECK,
        flowCheck: HOME_FLOW_CHECK,
        flowStart: HOME_FLOW_START,
      });
      const methods = {
        watchFlowType(type) {
          state.curFlowType = type;
        },
      };
      onMounted(() => {
        VueEvent.on(HOME_FLOW_SWITCH, methods.watchFlowType);
      });
      onBeforeUnmount(() => {
        VueEvent.off(HOME_FLOW_SWITCH);
      });

      return {
        ...toRefs(state),
        ...methods,
      };
    },
  });
</script>
<style scoped lang="less">
  .child-left-header {
    width: 210px;
    height: 54px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    font-size: 16px;
    border-top: 1px solid #ecedf0;
    border-left: 1px solid #ecedf0;
    border-right: 1px solid #ecedf0;
    img {
      width: 16px;
      height: 16px;
    }
    span {
      line-height: 16px;
      padding-left: 8px;
      font-weight: bold;
      color: @primary-color;
    }
  }
  .child-border-bottom {
    border-bottom: 1px solid #ecedf0;
  }
</style>
